/**
 * 可外部配置的路由定义适配器
 * 根据业务事件响应跳转对应路由地址
 */
import Navigo from 'navigo';
import ComponentRender from './render';
import RouterMap from './map';

const router = new Navigo(null, true);

for (let type in RouterMap) {
  for (let name in RouterMap[type]) {
    router.on({
      [RouterMap[type][name].url]: {
        as: `${type}.${name}`,
        uses: () => new ComponentRender(RouterMap[type][name].component)
      }
    })
  }
}
router.resolve();

export const url = (alias, params) => router.generate(alias, params);